/*********************************************************************
* File: Properties.cpp
*
* \brief Provides properties management.
*
* \author Instituto Superior Tecnico de Lisboa, Portugal
* \author Technical University of Lisbon, Portugal
* 
* \author Agentes Autonomos e Sistemas Multiagente
* \author Autonomous Agents and Multiagent Systems
* 
* \version	1.0
* \date		2006/2007
*********************************************************************/
#include "Properties.h"
#include "ioLibrary.h"
using namespace util;

#pragma warning( disable : 4996 )  // Disable warning messages

/** 
* \brief The class constructor.
**/
Properties::Properties(const char* file)
{
	string line;
	string propertyName, propertyValue;
	int indexOfSeparator;

	char buffer[512];
	FILE* sIn = fopen(file, "r");

	while(util::io::getLine(sIn, buffer))
	{
		line = buffer;
		if(line.find_first_of("#") == 0)
			continue;
		indexOfSeparator = line.find_first_of("=");
		propertyName = line.substr(0, indexOfSeparator);
		propertyValue = line.substr(indexOfSeparator + 1, line.size());
		_properties[propertyName] = propertyValue;
	}

	fclose(sIn);
}

/** 
* \brief Gets a property.
* 
* \param[in] key The property key. 
**/
string Properties::getProperty(string key)
{
	return _properties[key];
}